package com.itheima.web.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Xiao
 * @date 2021/8/29
 */

/**
 * Request获取请求数据--获取请求行数据
 * 	获取请求方式：String getMethod()
 * 	获取虚拟目录(项目访问路径)：String getContextPath()
 * 	获取URL(统一资源定位符)：StringBuffer getRequestURL()
 * 	获取URI(统一资源标识符)：String getRequestURI()
 * 	获取请求参数(GET方式)：String getQueryString()
 */
@WebServlet("/demo03")
public class RequestDemo03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getMethod();    //GET
        String path = req.getContextPath(); ///request_response
        StringBuffer url = req.getRequestURL(); //http://localhost:8080/request_response/demo03
        String uri = req.getRequestURI();   ///request_response/demo03
        String query = req.getQueryString();    //username=zhangsan
        System.out.println(method);
        System.out.println(path);
        System.out.println(url);
        System.out.println(uri);
        System.out.println(query);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("demo02-post...");
    }
}
